import 'package:trade/common/service/td_service.dart';
import 'package:trade/pages/login_page/login_page.dart';
import 'package:trade/pages/trading_page/trading_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class NavigationPage extends StatefulWidget {
  @override
  _NavigationPageState createState() => _NavigationPageState();
}

class _NavigationPageState extends State<NavigationPage>
    with SingleTickerProviderStateMixin {

  List<Widget> _pages = [LoginPage(), TradingPage(),];
  int _indexNum = 0;

  @override
  void didChangeDependencies() {
    service.router.overlayContext = context;
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [_getPageWidget(0), _getPageWidget(1)],
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.monetization_on),
            label: 'login',
            activeIcon: Icon(Icons.monetization_on_outlined),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.monetization_on),
            label: 'trade',
            activeIcon: Icon(Icons.monetization_on_outlined),
          ),
        ],
        iconSize: 24,
        currentIndex: _indexNum,
        fixedColor: Colors.lightBlueAccent,
        type: BottomNavigationBarType.fixed,
        onTap: (index) {
          if (_indexNum != index) {
            setState(() {
              _indexNum = index;
            });
          }
        },
      ),
    );
  }

  Widget _getPageWidget(int index) {
    return Offstage(
      offstage: _indexNum != index,
      child: TickerMode(
        enabled: _indexNum == index,
        child: _pages[index],
      ),
    );
  }
}
